package com.google.zxing.client.android;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.GridView;

public class ImageResult extends Activity {
	private String result = new String();
	private GridView gridViewResult;
	private ArrayList<Integer> resultIds = new ArrayList<Integer>();

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// overridePendingTransition(R.anim.popup_show, R.anim.popup_hide);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.result_image);
		this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

		if (getIntent().getSerializableExtra("images") != null && getIntent().getSerializableExtra("images").toString().length() > 0) {
			result = getIntent().getSerializableExtra("images").toString();
		}

		decodeResult();
		gridViewResult = (GridView) findViewById(R.id.imageGrid);
		gridViewResult.setAdapter(new GridAdapter(getBaseContext(), resultIds));
	}

	private void decodeResult() {

		for (int i = 0; i < 153; i += 3) {

			String idName = new String();
			String imageName = new String();

			if (result.length() >= i + 3) {
				imageName = result.substring(i, i + 3);

				if (imageName != null && imageName.length() > 0 && !"050".equals(imageName)) {
					idName = "image_" + imageName;

					Log.i("IDNAME", idName);
					int id = getBaseContext().getResources().getIdentifier(idName, "drawable", this.getPackageName());

					resultIds.add(id);
				}
			}

		}

	}
}
